import random

from DrissionPage import ChromiumPage
import time


def get_cookies():
    page = ChromiumPage()
    list = []
    page.get('https://data.10jqka.com.cn/funds/ggzjl/')
    str1 = ''
    for cookie in page.cookies():
        str1 = str1 + cookie['name'] + '=' + cookie['value'] + ';'
    list.append(str1)
    s1 = random.randint(1, 9) * random.randint(1, 9)
    print('准备休眠：' + str(s1))
    time.sleep(s1)
    page.get('https://data.10jqka.com.cn/funds/gnzjl/#refCountId=data_55f13c2c_254')
    str2 = ''
    for cookie in page.cookies():
        str2 = str2 + cookie['name'] + '=' + cookie['value'] + ';'
    list.append(str2)
    s2 = random.randint(1, 9) * random.randint(1, 9)
    print('准备休眠：' + str(s2))
    time.sleep(s2)
    page.get('https://data.10jqka.com.cn/market/rzrq/')
    str3 = ''
    for cookie in page.cookies():
        str3 = str3 + cookie['name'] + '=' + cookie['value'] + ';'
    list.append(str3)
    return list


def get_headers_rzrq(header):
    page = ChromiumPage()
    headers = []
    page.get('https://data.10jqka.com.cn/funds/ggzjl/')
    str1 = ''
    for cookie in page.cookies():
        str1 = str1 + cookie['name'] + '=' + cookie['value'] + ';'
        header[0]['Cookie'] = str1
    headers.append(header[0])
    s1 = random.randint(1, 5) * random.randint(1, 7)
    print('准备休眠：' + str(s1))
    time.sleep(s1)
    page.get('https://data.10jqka.com.cn/funds/gnzjl/#refCountId=data_55f13c2c_254')
    str2 = ''
    for cookie in page.cookies():
        str2 = str2 + cookie['name'] + '=' + cookie['value'] + ';'
        header[1]['Cookie'] = str2
    headers.append(header[1])
    s2 = random.randint(1, 6) * random.randint(1, 8)
    print('准备休眠：' + str(s2))
    time.sleep(s2)
    page.get('https://data.10jqka.com.cn/market/rzrq/')
    str3 = ''
    for cookie in page.cookies():
        str3 = str3 + cookie['name'] + '=' + cookie['value'] + ';'
        header[2]['Cookie'] = str3
    headers.append(header[2])
    return headers


def get_header_for_all_stock_price():
    page = ChromiumPage()
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'Host': 'q.10jqka.com.cn',
        'Referer': 'https://q.10jqka.com.cn/',
        'Connection': 'keep-alive',
        'Cookie': 'Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1720661055,1720761405,1721093382; HMACCOUNT=F7AF1D7A4FC9FA26; Hm_lvt_722143063e4892925903024537075d0d=1721638592; Hm_lvt_929f8b362150b1f77b477230541dbbc2=1721638592; Hm_lpvt_722143063e4892925903024537075d0d=1721692216; Hm_lpvt_929f8b362150b1f77b477230541dbbc2=1721692216; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1722300654; v=A6aC2I5h_JiOKKg8tEgPwayd9xcth-pAvMsepZBPkkmkE0iJ-Bc6UYxbbrNj; u_ukey=A10702B8689642C6BE607730E11E6E4A; u_uver=1.0.0; u_dpass=zFSy4TlMFZ9G72hqTqT7wzj%2FfeFNGbKXc3G3oG4FhZV5kcNetCGjHjeLdqu6bMJMHi80LrSsTFH9a%2B6rtRvqGg%3D%3D; u_did=F0FCE7149D344C45A77974075615E87E; u_ttype=WEB'
        # 这里可以添加更多的header信息
    }
    page.get('https://q.10jqka.com.cn/')

    str1 = ''
    for cookie in page.cookies():
        str1 = str1 + cookie['name'] + '=' + cookie['value'] + ';'
    # headers['Cookie'] = headers['Cookie'] + str1
    sleep = random.randint(1, 5)*random.randint(1, 5)
    print('获取header完成，准备休眠：' + str(sleep))
    time.sleep(sleep)
    # 关闭浏览器
    page.quit()
    return headers


